package com.atguigu.gmall.product.rest;

import com.atguigu.gmall.common.constant.RedisConst;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.SkuInfo;
import com.atguigu.gmall.product.service.SkuInfoService;
import com.atguigu.gmall.product.vo.SaveSkuVo;
import com.atguigu.starter.cache.service.BitmapService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author lfy
 * @Description
 * @create 2023-08-16 11:38
 */
@RequestMapping("/admin/product")
@RestController
public class SkuController {


    @Autowired
    SkuInfoService skuInfoService;

    @Autowired
    BitmapService bitmapService;


    /**
     * 初始化位图
     * @return
     */
    @GetMapping("/init/sku/bitmap")
    public Result initSkuIdsBitMap(){

        skuInfoService.initSkuIdsBitMap();

        return Result.ok();
    }


    /**
     * 分页查询 sku 列表
     * @return
     */
    @GetMapping("/list/{pn}/{ps}")
    public Result skuList(@PathVariable("pn") Long pn,
                          @PathVariable("ps") Long ps){

        Page<SkuInfo> page = skuInfoService.page(new Page<SkuInfo>(pn, ps));

        return Result.ok(page);
    }

    /**
     * sku大保存
     * @return
     */
    @PostMapping("/saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SaveSkuVo vo){

        skuInfoService.saveSkuInfo(vo);
        return Result.ok();
    }


    /**
     * 上架
     * @param skuId
     * @return
     */
    @GetMapping("/onSale/{skuId}")
    public Result onSale(@PathVariable("skuId") Long skuId){

        skuInfoService.onSale(skuId);


        return Result.ok();
    }


    /**
     * 下架
     * @param skuId
     * @return
     */
    @GetMapping("/cancelSale/{skuId}")
    public Result cancelSale(@PathVariable("skuId") Long skuId){

        skuInfoService.cancelSale(skuId);


        return Result.ok();
    }
}
